Cycle through Baseline Object Links

Hello. I currently trying to cycle through all the links in the previous baseline of a module but I keep getting a runtime error right when my for loop hits the second object.  My code works perfectly fine for objects that havent been baselined yet but that's not what I want.  Any help would be much appreciated.

 

EDIT: Error: -R-E- DXL:<Line:22> null Object parameter was passed into argument position 1
Backtrace:
    <Line:114> 
-I- DXL: execution halted

 

 

Here is the basics of my code:

 

pragma runLim, 0

Object o
LinkRef lr 
Link l 

Module m = current Module

 

for o in m do {

       int absn = o."Absolute Number"

 

       Module a = current Module
       Baseline b = getMostRecentBaseline(a)
       Module oldMod = load(b, false)
       Object baseObj = object(absn, oldMod)

 

       for lr in all(baseObj<-"*") do {
             otherMod = module (sourceVersion lr)
             if (!null otherMod){
             load((sourceVersion lr),false)
             }
       }
    
       for l in all (baseObj <-"*") do {                 //Here is Line 22 for the Error I am getting
             Object sourceObj = source(l)
             int absn2 = sourceObj."Absolute Number"
             string sourcePath = path(module(sourceObj))

             print("\n"absn2"\n")    
      }

}

 


ABoucaud - Fri Jan 13 13:52:48 EST 2017

Re: Cycle through Baseline Object Links
Mike.Scharnow - Fri Jan 13 14:24:10 EST 2017

it's most probably your variable a. when you load the baseline (oldMod = load(b, false)), your current module is changed. You do not need variable a at all, as you have variable m.Use it when setting variable b.

Re: Cycle through Baseline Object Links
ABoucaud - Fri Jan 13 14:31:48 EST 2017

Mike.Scharnow - Fri Jan 13 14:24:10 EST 2017

it's most probably your variable a. when you load the baseline (oldMod = load(b, false)), your current module is changed. You do not need variable a at all, as you have variable m.Use it when setting variable b.

Yeah your right, I dont need variable a.  I took that line out and pointed towards m instead and i got this error:

-R-E- DXL: <Line:13> null Module parameter was passed into argument position 2
-I- DXL: execution halted

 

where Line 13 is: Object baseObj = object(absn, oldMod)

EDIT: I'm still able to process the first object perfectly fine. Its when I get to the second object that this happens. This problem has me completely stumped because I can successfully cycle through other attributes of the baselined objects perfectly fine.  This only happens when I try to cycle through the links.

Re: Cycle through Baseline Object Links
Mike.Scharnow - Sat Jan 14 03:01:19 EST 2017

Of course there are more possibilities to improve the code, e.g. you should not set variables b and oldMod inside the loop, but rather outside, as they will be identical for each o in m.

And you should test whether e.g. the baseline was set correctly by checking it against null. 

One important thing: with "Module oldMod=..." your current Module will be the new baseline. So, when you run the script once, the current Module will have changed. Before you run the script a second time, you have to make sure that the opened baseline is closed again.

And: "Object baseObj = object ..." might also return a null object, e.g. when the object is new in the current version and does not exist in the baseilne.

This code runs in my test module.

pragma runLim, 0
Object o
LinkRef lr 
Link l 
Module m = current Module
print version (m) "\n"
       Baseline b = getMostRecentBaseline(m)
print major(b) "." minor(b) "\n"
       Module oldMod = load(b, fals
if (null oldMod) {error "null module"}
 
for o in m do {
       int absn = o."Absolute Number"
 
       Object baseObj = object(absn, oldMod)
if (null baseObj) {warn "null object of " absn "\n";continue}
print "I found object " absn" in baselinne " major(b) "." minor(b) " " suffix(b) "\n"

       for lr in all(baseObj<-"*") do {
             otherMod = module (sourceVersion lr)
             if (!null otherMod){
             load((sourceVersion lr),false)
             }
       }
    
       for l in all (baseObj <-"*") do {                 //Here is Line 22 for the Error I am getting
             Object sourceObj = source(l)
             int absn2 = sourceObj."Absolute Number"
             string sourcePath = path(module(sourceObj))
             print("\n"absn2"\n")    
      }
}
close oldMod

 

Re: Cycle through Baseline Object Links
ABoucaud - Tue Jan 24 13:10:45 EST 2017

Mike.Scharnow - Sat Jan 14 03:01:19 EST 2017

Of course there are more possibilities to improve the code, e.g. you should not set variables b and oldMod inside the loop, but rather outside, as they will be identical for each o in m.

And you should test whether e.g. the baseline was set correctly by checking it against null. 

One important thing: with "Module oldMod=..." your current Module will be the new baseline. So, when you run the script once, the current Module will have changed. Before you run the script a second time, you have to make sure that the opened baseline is closed again.

And: "Object baseObj = object ..." might also return a null object, e.g. when the object is new in the current version and does not exist in the baseilne.

This code runs in my test module.

pragma runLim, 0
Object o
LinkRef lr 
Link l 
Module m = current Module
print version (m) "\n"
       Baseline b = getMostRecentBaseline(m)
print major(b) "." minor(b) "\n"
       Module oldMod = load(b, fals
if (null oldMod) {error "null module"}
 
for o in m do {
       int absn = o."Absolute Number"
 
       Object baseObj = object(absn, oldMod)
if (null baseObj) {warn "null object of " absn "\n";continue}
print "I found object " absn" in baselinne " major(b) "." minor(b) " " suffix(b) "\n"

       for lr in all(baseObj<-"*") do {
             otherMod = module (sourceVersion lr)
             if (!null otherMod){
             load((sourceVersion lr),false)
             }
       }
    
       for l in all (baseObj <-"*") do {                 //Here is Line 22 for the Error I am getting
             Object sourceObj = source(l)
             int absn2 = sourceObj."Absolute Number"
             string sourcePath = path(module(sourceObj))
             print("\n"absn2"\n")    
      }
}
close oldMod

 

I've been pretty busy at work with other tasks so I haven't been able to respond any sooner. But it seems that setting the baseline outside of the object for loop such that it is only set once (like in your example) really hit the sweet spot!!

Thank you very much!